#include "sysconfig.h"
#include "FloppiesSounds.h"

using namespace System;
using namespace AmiEmuLib::Configuration::FloppySoundConfig;

namespace CLR
{
    namespace FloppiesSounds
    {
        void GetSoundsSamplesList(CArray<CString>* a_res)
        {
            a_res->RemoveAll();

            for each(FloppySounds ^ fs in FloppySoundsList::List)
            a_res->Add(CString(fs->Name));
        }

        byte * ConvertArray(array<byte>^ ar, int* size)
        {
            if (ar == nullptr)
            {
                *size = 0;
                return nullptr;
            }

            *size = ar->Length;
            byte* b = new byte[ar->Length];
            System::Runtime::InteropServices::Marshal::Copy(
                ar, 0, (IntPtr)b, ar->Length);
            return b;
        }

        byte * LoadClick(CString a_name, int* size)
        {
            return ConvertArray(FloppySoundsList::GetSounds(gcnew String(a_name))->Click->GetBytes(), size);
        }

        byte * LoadSnatch(CString a_name, int* size)
        {
            return ConvertArray(FloppySoundsList::GetSounds(gcnew String(a_name))->Snatch->GetBytes(), size);
        }

        byte * LoadSpin(CString a_name, int* size)
        {
            return ConvertArray(FloppySoundsList::GetSounds(gcnew String(a_name))->Spin->GetBytes(), size);
        }

        byte * LoadSpinNoDisk(CString a_name, int* size)
        {
            return ConvertArray(FloppySoundsList::GetSounds(gcnew String(a_name))->SpinNoDisk->GetBytes(), size);
        }

        byte * LoadStartup(CString a_name, int* size)
        {
            return ConvertArray(FloppySoundsList::GetSounds(gcnew String(a_name))->Startup->GetBytes(), size);
        }
    }
}